﻿using Lis.DTO;
using Lis.IBLL;
using Lis.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace Lis.WebApp.Controllers
{
    public class BorrowController : ApiController
    {
        public IBorrowBookService BorrowBookService { get; set; }
        
        #region 01，图书借阅+ServiceResult<string> BorrowBook(string value, string value1)
        /// <summary>
        /// 图书借阅
        /// </summary>
        /// <param name="value">读者卡号</param>
        /// <param name="value1">馆藏号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<string> BorrowBook(string value, string value1)
        {
            try
            {
                var borrowBookDto = new BorrowBookDto()
                    {
                        UserName = value,
                        BarCode = value1
                    };

                return BorrowBookService.BorrowBookByBarCode(borrowBookDto);
            }
            catch (Exception)
            {
                return new ServiceResult<string>()
                {
                    Success = false,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 02，图书续借+ServiceResult<string> ReNewBook(string value, string value1)
        /// <summary>
        /// 图书续借
        /// </summary>
        /// <param name="value">读者卡号</param>
        /// <param name="value1">馆藏号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<string> ReNewBook(string value, string value1)
        {
            try
            {
                var borrowBookDto = new BorrowBookDto()
                    {
                        UserName = value,
                        BarCode = value1
                    };

                return BorrowBookService.ReNewBookByBarCode(borrowBookDto);
            }
            catch (Exception)
            {
                return new ServiceResult<string>()
                {
                    Success = false,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 03，图书转借+ServiceResult<string> LendBook(string value, string value1, string value2)
        /// <summary>
        /// 图书转借
        /// </summary>
        /// <param name="value">还书人</param>
        /// <param name="value1">借书人</param>
        /// <param name="value2">馆藏号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<string> LendBook(string value, string value1, string value2)
        {
            try
            {
                var borrowBookDto = new BorrowBookDto()
                {
                    UserName = value1,
                    ReturnUserName = value,
                    BarCode = value2
                };

                return BorrowBookService.LendBookByBarCode(borrowBookDto);
            }
            catch (Exception)
            {
                return new ServiceResult<string>()
                {
                    Success = false,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion
    }
}
